﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UCWebpart.Admin
{
    public partial class OtherControl : System.Web.UI.UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["userName"] == null)
            {
                Response.Redirect("../Login.aspx", false);
                return;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(TextBox1.Text))
            {
                return;
            }
            try
            {
                string newType = TextBox1.Text;
                using (var mtrtype = new meetingroomManagementEntities())
                {
                    MTR_bas_Type bt = new MTR_bas_Type();
                    bt.Type = TextBox1.Text;
                    bt.available = true;

                    mtrtype.MTR_bas_Type.Add(bt);
                    mtrtype.SaveChanges();
                    Response.Write("<script>alert('场地类型添加成功！'); </script>");
                    Response.Redirect("OtherManage.aspx", false);
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "'); </script>");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(TextBox2.Text))
            {
                return;
            }
            try
            {
                string newType = TextBox2.Text;
                using (var mtrtype = new meetingroomManagementEntities())
                {
                    MTR_bas_AddressName bt = new MTR_bas_AddressName();
                    bt.addressName = TextBox2.Text;
                    bt.available = true;

                    mtrtype.MTR_bas_AddressName.Add(bt);
                    mtrtype.SaveChanges();
                    Response.Write("<script>alert('地址添加成功！'); </script>");
                    Response.Redirect("OtherManage.aspx",false);
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('"+ex.Message+"'); </script>");
            }
        }
    }
}